<template>
	<div>
		<el-form ref="form" :model="form" label-width="80px">
			<el-form-item label="指标名称">
				<el-input v-model="form.name"></el-input>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" @click="findList">查询</el-button>
				<el-button>取消</el-button>
			</el-form-item>
		</el-form>

		<el-button type="text" @click="dialogVisible = true">添加</el-button>

		<el-table :data="indexManagementList" style="width: 100%">
			<el-table-column prop="id" label="Id" width="180">
			</el-table-column>
			<el-table-column prop="name" label="指标姓名" width="180">
			</el-table-column>
			<el-table-column prop="unit" label="指标单位">
			</el-table-column>
			<el-table-column prop="unit" label="指标单位">
			</el-table-column>

			<el-table-column prop="upper" label="上限">
			</el-table-column>

			<el-table-column prop="lower" label="下限">
			</el-table-column>

			<el-table-column prop="normalPrompt" label="正常提示">
			</el-table-column>

			<el-table-column prop="highAlert" label="偏高提示">
			</el-table-column>

			<el-table-column prop="lowAlert" label="偏低提示">
			</el-table-column>

			<el-table-column prop="toCompare" label="是否比对">

				<template slot-scope="scope">
					<span>{{scope.row.toCompare==0?'否':'是'}}</span>
				</template> 

			
			</el-table-column>
		</el-table>


		<el-dialog title="添加" :visible.sync="dialogVisible" width="30%" :before-close="handleClose">
			
			<el-form ref="form" :model="addform" label-width="80px">
			  <el-form-item label="指标名称">
			    <el-input v-model="addform.name"></el-input>
			  </el-form-item>
			  
			  
			  <el-form-item label="是否比对">
			    <el-switch v-model="addform.toCompare"
				active-value ="1" inactive-value="0"></el-switch>
			  </el-form-item>
			  
			  <el-form-item label="指标单位">
			    <el-input v-model="addform.unit"></el-input>
			  </el-form-item>
			  
			  
			  <el-form-item label="指标上限">
			    <el-input v-model="addform.upper"></el-input>
			  </el-form-item>
			  
			  
			  <el-form-item label="指标下限">
			    <el-input v-model="addform.lower"></el-input>
			  </el-form-item>
			  
			  <el-form-item label="正常提示">
			    <el-input v-model="addform.normalPrompt"></el-input>
			  </el-form-item>
			  
			  <el-form-item label="偏高提示">
			    <el-input v-model="addform.highAlert"></el-input>
			  </el-form-item>
			  
			  <el-form-item label="偏低提示">
			    <el-input v-model="addform.lowAlert"></el-input>
			  </el-form-item>
			  
			  
		
			
			</el-form>
			
			
			
			<span slot="footer" class="dialog-footer">
				<el-button @click="dialogVisible = false">取 消</el-button>
				<el-button type="primary" @click="add()">保存/确 定</el-button>
			</span>
			
			
		</el-dialog>

	</div>
</template>

<script>
	import axios from "axios"
	export default {
		data() {
			return {
				indexManagementList: [],
				form: {
					name: ''
				},
				dialogVisible: false,
				addform:{
					name:'',
					toCompare:'',
					unit:'',
					upper:'',
					lower:'',
					normalPrompt:'',
					lowAlert:'',
					highAlert:''
					
				}
			}
		},
		methods: {
			findList() {
				axios.get('http://localhost:21010/api-im/api/indexManagement/list?name=' + this.form.name).then(res => {
					this.indexManagementList = res.data.data;
				})
			},
			add(){
				//if()
				axios.post('http://localhost:21010/api-im/api/indexManagement/save',this.addform).then(res=>{
					if(res.data.code==1){
						this.$message({
						          message: '恭喜你，添加 成功',
						          type: 'success'
						        });
								
							this.dialogVisible = false
								
					}else{
						this.$message({
						          message: '添加失败'
						        });
					}
				})
			},
			   handleClose(done) {
			        this.$confirm('确认关闭？')
			          .then(_ => {
			            done();
			          })
			          .catch(_ => {});
			      }
			    
		},
		created() {
			this.findList();

		}
	}
</script>

<style>
</style>